﻿using System;
using System.Collections.Generic;
using System.Text;

namespace OpenGameEngine
{
    public struct SolidColorBrush : IDisposable
    {
        public float Opacity;
        public Color Color;
        private bool _disposed;

        public SolidColorBrush(Color c)
        {
            Opacity = 1.0f;
            Color = c;
            _disposed = false;
        }

        public SolidColorBrush(Color c, float opacity)
        {
            Color = c;
            Opacity = opacity;
            _disposed = false;
        }

        public static implicit operator SharpDX.Direct2D1.SolidColorBrush(SolidColorBrush scb)
        {
            SharpDX.Direct2D1.BrushProperties bp = new SharpDX.Direct2D1.BrushProperties();
            bp.Opacity = scb.Opacity;

            //using (SharpDX.Direct2D1.SolidColorBrush _scb = new SharpDX.Direct2D1.SolidColorBrush(GameEngine._renderTarget, (SharpDX.Color4)((SharpDX.Color)scb.Color), bp))
            //{
            //    return _scb;
            //}
            return new SharpDX.Direct2D1.SolidColorBrush(Globals.RenderTarget, (SharpDX.Color4)((SharpDX.Color)scb.Color), bp);
        }

        public void Dispose()
        {
            Dispose(true);

            GC.SuppressFinalize(this);
        }

        private void Dispose(bool disposing)
        {
            if (!_disposed)
            {
                if (disposing)
                {
                    Color = Color.Zero;
                    Opacity = 0;
                }
            }
        }
    }
}
